package com.restart.game.controller;

import com.restart.game.entity.Conf;
import com.restart.game.entity.InfoType;
import com.restart.game.mapper.InfoTypeMapper;
import com.restart.game.service.ConfService;
import com.restart.game.service.InfoTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author ReStartLin
 * @data 2018/12/7 11:15
 * @classDesc: 功能描述:
 */
@Controller
public class MainController {
    public static final Logger logger = LoggerFactory.getLogger(MainController.class);
    private final InfoTypeService infoTypeService;

    private final ConfService confService;
    private final InfoTypeMapper infoTypeMapper;

    @Autowired
    public MainController(InfoTypeService infoTypeService, ConfService confService, InfoTypeMapper infoTypeMapper) {
        this.infoTypeService = infoTypeService;
        this.confService = confService;
        this.infoTypeMapper = infoTypeMapper;
    }


    @RequestMapping("/index")
    public String index() {
        return "/index";
    }


    @RequestMapping("/info/search")
    public String searchInfo(Model model) {
        return "/info/searchInfo";
    }


    @RequestMapping("/info/conf")
    public String setConf(Model model) {
        List<Conf> all = confService.findAll();
        if (all != null && all.size() > 0) {
            model.addAttribute("conf", all.get(0));
        }
        return "/info/conf";
    }

    @RequestMapping("/info/success")
    public String success() {
        return "/info/success";
    }
    @RequestMapping("/info/info")
    public String info(Model model) {
        Example example = new Example(InfoType.class);
        example.orderBy("count");
        List<InfoType> infoTypes = infoTypeMapper.selectByExample(example);

        model.addAttribute("infoTypes", infoTypes);
        return "info/info";
    }

}
